// 注册echarts实例Hooks
import cache from '@/utils/cache'

import * as echarts from 'echarts'

// 注册使用中国地图
import chinaMapData from '@/base-ui/echarts/data/china.json'

echarts.registerMap('china', chinaMapData)

export default function (el: HTMLElement): any {
  // 实例化echarts
  // 颜色主题
  // const bgc = cache.getItem('bgcColor')

  // const echartsInstance =
  //   bgc.color === '#000' ? echarts.init(el!) : echarts.init(el!, 'dark')
  const echartsInstance = echarts.init(el!)
  // 调用
  const setOptions = (option: echarts.EChartsOption) =>
    echartsInstance.setOption(option)

  // 自定义变化
  const echartResize = () => echartsInstance.resize()

  window.addEventListener(
    'resize',
    () => {
      echartsInstance.resize()
    },
    false
  )

  return {
    echartsInstance,
    setOptions,
    echartResize
  }
}
